home *** CD-ROM | disk | FTP | other *** search
- unit MinDirX1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- DirectX, StdCtrls, ExtCtrls, ComObj;
-
- type
-
- TFrmMain = class(TForm)
- Timer1: TTimer;
-
- procedure FormCreate(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- public
- D3DRM: IDirect3DRM;
- Scene, Camera, Lights, MyVisualObject: IDirect3DRMFrame;
- MeshBuilder: IDirect3DRMMeshBuilder;
- Light1: IDirect3DRMLight;
- View: IDirect3DRMViewPort;
- DDClipper: IDirectDrawClipper;
- end;
-
- var
- frmMain: TfrmMain;
- Dev: IDirect3DRMDevice;
-
- implementation
-
-
-
- {$R *.DFM}
-
- procedure TfrmMain.FormCreate(Sender: TObject);
- begin
- // Create the IDirect3DRM interface from
- // which other interfaces are created and managed.
- Direct3DRMCreate(D3DRM);
-
- // Create frames to provide location and velocity for
- // each visual element in the 3D landscape.
- D3DRM.CreateFrame(Nil, Scene);
- D3DRM.CreateFrame(Scene, Lights);
- D3DRM.CreateFrame(Scene, Camera);
- D3DRM.CreateFrame(Scene, MyVisualObject);
-
- // These next steps create an IDirect3DRMDevice that
- // keeps track of hardware/software capabilities,
- // and the window area thatÆs being drawn to.
- DirectDrawCreateClipper(0, DDClipper, Nil);
- DDClipper.SetHWnd(0, Handle);
- D3DRM.CreateDeviceFromClipper(DDClipper, Nil, ClientWidth, ClientHeight, Dev);
-
- // Create a 3D visible object, add it to the scene,
- // and give it a spin.
- D3DRM.CreateMeshBuilder(MeshBuilder);
- MeshBuilder.Load(PChar('Egg.x'), Nil, D3DRMLOAD_FROMFILE, Nil, Nil);
- MyVisualObject.AddVisual(IDirect3DRMVisual(MeshBuilder));
- MyVisualObject.SetRotation(Scene, 1, 1, 1, 0.01);
-
- // Add a light and attach the light to a frame.
- // Forgetting this step makes for a fully functioning,
- // but extremely boring display.
- D3DRM.CreateLightRGB(D3DRMLIGHT_DIRECTIONAL, 0.03, 0.9, 0.9, Light1);
- Lights.AddLight(Light1);
-
- // The viewport defines how a 3D scene is rendered to a 2D window.
- // The position and orientation of the second parameter (Camera)
- // defines the point-of-view of the user.
- D3DRM.CreateViewPort(Dev, Camera, 0, 0, ClientWidth, ClientHeight,
- View);
- Camera.SetPosition(Scene, 0, 0, -7);
-
- Timer1.Interval := 1;
- end;
-
- // The Tick method actually encapsulates four other tasks:
- // IDirect3DRMFrame.Move: Reposition frames according to rotation and // velocity.
- // IDirect3DRMViewport.Clear: Clear the viewport to the current
- // background color.
- // IDirect3DRMViewport.Render: Draw the 3D scene to memory.
- // IDirect3DRMDevice.Update: Copy the rendered scene to the window.
- procedure TfrmMain.Timer1Timer(Sender: TObject);
- begin
- D3DRM.Tick(1.0);
- end;
-
- end.
-
-